package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.CourseReply;
import cn.hl.sfzy.entity.CourseTalk;
import cn.hl.sfzy.entity.User;
import cn.hl.sfzy.mapper.CourseReplyMapper;
import cn.hl.sfzy.mapper.CourseTalkMapper;
import cn.hl.sfzy.mapper.UserMapper;
import cn.hl.sfzy.service.CourseReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CourseReplyServiceImpl
 * @Description TODO
 * @Author libowen
 * @Date 2024年10月29日 10:40
 * @Version 1.0
 */
@Service
public class CourseReplyServiceImpl implements CourseReplyService {

    @Autowired
    private CourseReplyMapper courseReplyMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<CourseReply> findByTalkId(int pageNum, int pageSize, Long talk_id) {
        PageHelper.startPage(pageNum, pageSize);
        List<CourseReply> list = courseReplyMapper.selectByTalkId(talk_id);
        for(CourseReply cr : list){
            User user =
                    userMapper.selectById(cr.getUser_id());
            cr.setUser(user);
        }
        PageInfo<CourseReply> info = new PageInfo<>(list);
        return info;
    }
}
